package com.jack.thinking.thread.core._5;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

public class SchedulerAtFixedRunAfter {
	private static Timer timer = new Timer();
	public static void main(String[] args) throws Exception {
		MyTask2 task1 = new MyTask2();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = "2019-01-06 17:32:01";
		Date dateRef = sdf.parse(dateString);
		System.out.println("target time:" + dateRef + " system time:" + new Date());
		timer.scheduleAtFixedRate(task1, dateRef, 3000);
	}
}

class MyTask2 extends TimerTask{
	public static AtomicInteger n = new AtomicInteger(0);
	@Override
	public void run() {
		System.out.println(n.incrementAndGet() + " begin , time is " + new Date());
		try {
			Thread.sleep(2000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(n.get() + "   end , time is " + new Date());
	}
	
}